import { h, render } from 'vue'
import XtxConfirm from './confirm.vue'
//1、创建盛放组件的容器
const divDom = document.createElement('div')
divDom.className = 'xtx-config-box-contain-ma'
document.body.appendChild(divDom)
// 2、创建并导出一个confirm函数
// 2.1创建虚拟dom 基于confirm.vue
// 2.2挂载虚拟dom
type paramsType = { title: string, text: string }
export default function Confirm({ title, text }: paramsType) {
  return new Promise((resolve, reject) => {
    const confirmCallback = () => {
      // console.log(1);
      resolve("resolve")
      render(null, divDom)
    }
    const cancelCallback = () => {
      // console.log(2);
      reject('reject')
      render(null, divDom)
    }
    const VNode = h(XtxConfirm, { title, text, cancelCallback, confirmCallback })
    render(VNode, divDom)
  })
}